//
//  CYYDateAlterView.m
//  LetsParty
//
//  Created by YG on 15/9/13.
//  Copyright (c) 2015年 LetsPartyTeam. All rights reserved.
//

#import "CYYDateAlterView.h"

@interface CYYDateAlterView ()

//@property (nonatomic, strong) UIDatePicker * datePicker;
//@property (nonatomic, strong) UIButton * okButton;//确定按钮

- (void)initializeUserInterface;

@end

@implementation CYYDateAlterView

#pragma mark - initializer      初始化
- (instancetype)init{
    if (self = [super init]) {
        [self initializeUserInterface];
    }
    return self;
}

#pragma mark - private methods
- (void)initializeUserInterface{
    self.backgroundColor = [UIColor whiteColor];
    self.frame = DHFlexibleFrame(CGRectMake(35 , 60, 250, 300), NO);
    self.layer.borderWidth = 0.5f;
    self.layer.borderColor = [UIColor darkGrayColor].CGColor;
    [self addSubview:self.datePicker];
    [self addSubview:self.okButton];
    
}
//#pragma mark - responds to event
//- (void)respondsToOkButton:(UIButton *)button{
//    //date转换成string
//    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init];
//    [dateFormatter setDateFormat:@"yyyy/MM/dd"];
//    NSString * dateString = [dateFormatter stringFromDate:self.datePicker.date];
//    self.okDateBlock(dateString);
//    self.hidden = YES;
//}

#pragma mark - getter
- (UIDatePicker *)datePicker{
    if (!_datePicker) {
        _datePicker = ({
            UIDatePicker * datePicker = [[UIDatePicker alloc]init];
            datePicker.frame = DHFlexibleFrame(CGRectMake(0, 0, 250, 250), NO);
//            datePicker.datePickerMode = UIDatePickerModeDate;
//            [datePicker setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
            [datePicker setMinimumDate:[NSDate date]];
            [datePicker setDatePickerMode:UIDatePickerModeDate];
            /*
             Leaked Object	#	Address	Size	Responsible Library	Responsible Frame
             NSDateComponents	1	0x7feb233dc180	176 Bytes	UIKit	-[_UIDatePickerMode _yearlessYearForMonth:]
             */
            datePicker;
        });
    }
    return _datePicker;
}
-(UIButton *)okButton{
    if (!_okButton) {
        _okButton = ({
            UIButton * okButton = [UIButton buttonWithType:UIButtonTypeCustom];
            okButton.frame = DHFlexibleFrame(CGRectMake(0, 250, 250, 50), NO);
            [okButton setTitle:@"确定" forState:UIControlStateNormal];
            [okButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//            [okButton addTarget:self action:@selector(respondsToOkButton:) forControlEvents:UIControlEventTouchUpInside];
            okButton;
        });
    }
    return _okButton;
}

@end
